package com.tanhua.server.interceptor;

import com.tanhua.model.domain.User;

//工具类，向ThreadLocal存储数据
public class UserHolder {
    private static ThreadLocal<User> t1 = new ThreadLocal<>();

    //将用户对象，存入threadLocal
    public static void set(User user) {
        t1.set(user);
    }

    //从当前线程threadlocal，获取用户对象
    public static User get() {
        return t1.get();
    }

    //从当前线程threadlocal，获取用户对象的 id
    public static Long getUserId() {
        return t1.get().getId();
    }

    //从当前线程threadlocal，获取用户对象的 mobile
    public static String getMobile() {
        return t1.get().getMobile();
    }

    //清空threadlocal
    public static void remove() {
        t1.remove();
    }
}
